import http from '../module/http'
import { AxiosResponse } from 'axios'
interface Code { 
    code: number,
    msg:string
}
//登陆
export function login(name:string,password:string):Promise<AxiosResponse> { 
    return http({
        url: '/login',
        method: 'post',
        data:{name,password}
    })
}
//发送验证码
export function SendVerificationCode(mail:string):Promise<AxiosResponse<Code>> { 
    return http({
        url: 'https://api.it120.cc/jouei/verification/mail/get',
        params: {
           mail 
        },
        method:'get'
    })
}
//验证验证码
export function verification(code: string, mail: string): Promise<AxiosResponse<Code>> { 
    return http({
        url: 'https://api.it120.cc/jouei/verification/mail/check',
        data: { code, mail },
        method:'post'
    })
}
//用户注册
export function register(name: string, password: string): Promise<AxiosResponse> {
    return http({
        url: '/register',
        data: { name, password },
        method:'post'
    })
}
//获取用户信息
export function info() { 
    return http({
        headers: {
            token:localStorage.token
        },
        url: '/info',
        method:'post'
    })
}
//用户添加账号
export function addAccount(key: string,cookie:string,name:string) { 
    return http({
        url: '/addAccount',
        method: 'post',
        data: {
            key,
            cookie:JSON.stringify(cookie),
            name
        }
    })
        
}
//获取登录二维码key
export function getKey() { 
    return http({
        url: 'key',
        method:"post"
    })
}

//获取登录二维码地址
export function createUrl(key: string): Promise<AxiosResponse> { 
    return http({
        url: '/createUrl',
        method: 'post',
        data: {
            key
        }
    })
}
//轮询扫码状态
export function UrlState(key: string) { 
    return http({
        url: '/UrlState',
        method: 'post',
        data: {key}
    })
}
//获取用户配置
export function getConfiguration(account:string) { 
    return http({
        url: '/configuration',
        method: 'post',
        data: {
            account
        }
    })
}
//更新用户配置
export function updataConfig(key:string, value:Boolean,account:string) {
    return http({
        url: '/updataConfig',
        method: "post",
        data: {
            key,
            value,
            account
        }
    })
}
//续费账号
export function renew(key:string,account:string) { 
    return http({
        url: '/renew',
        method: 'post',
        data: {
            key,
            account
        }
    })
}
//获取用户全部日志
export function getAllLog() { 
    return http({
        headers: {
            token:localStorage.token
        },
        url: '/getAllLog',
        method: "post",
    })
}
//获取单个用户日志
export function getLog(account:string) { 
    return http({
        url: '/getLog',
        method: 'post',
        data: {account}
    })
}
//更新用户状态
export function updataState(account:string,cookie:string) { 
    return http({
        url: '/updataState',
        method: 'post',
        data: {account,cookie}
    })
}